package com.java.yz.day12.ketang;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

//Map 接口的哈希表和链接列表实现，具有可预知的迭代顺序。
public class LinkedHashMapDemo1 {
    public static void main(String[] args) {
        //创建集合对象
        LinkedHashMap<Student, String> Map = new LinkedHashMap<>();

        //添加集合元素
        Map.put(new Student("柳宗元",20),"看诗");
        Map.put(new Student("李清照",23),"读诗");
        Map.put(new Student("白居易",22),"想诗");
        Map.put(new Student("杜甫",26),"吟诗");
        Map.put(new Student("李白",24),"写诗");
        Map.put(new Student("李白",20),"写诗");
        //遍历集合
        Set<java.util.Map.Entry<Student, String>> entries = Map.entrySet();
        for (java.util.Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String name = key.getName();
            int age = key.getAge();
            String value = entry.getValue();
            System.out.println(name+"=="+age+"=="+value);
            /*发现它的输入输出顺序一致
                柳宗元==20==看诗
                李清照==23==读诗
                白居易==22==想诗
                杜甫==26==吟诗
                李白==24==写诗
                李白==20==写诗
             */
        }
    }
}
